import { ApiProperty } from "@nestjs/swagger";
import { Category } from "@prisma/client";
import { Transform } from "class-transformer";
import { IsInt, IsNotEmpty, IsOptional, IsString, Min } from "class-validator";

import { DbCommonField } from "@/core/types/db-common-field.type";

export class CreateCategoryDto implements CustomOmit<Category, DbCommonField | "id"> {
    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "分类名", example: "生活", required: true })
    name: string;

    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "分类代码", example: "life", required: true })
    code: string;

    @IsOptional()
    @Transform(({ value }) => value.trim())
    @IsString()
    @ApiProperty({ description: "分类描述", example: "生活相关的文章", required: false })
    description: string = "";

    @IsOptional()
    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(0)
    @ApiProperty({ description: "分类排序", example: 1, required: false })
    sort: number;
}
